//
// Created by Administrator on 2020/7/15.
//T6章:数组、指针与字符串(2)
//字符串
//C风格字符串(略)
//string类
//String类常用的构造函数:
//string();//默认构造函数,建立一个长度为0的串(eg:string s1;)
//string(const char *s);//用指针s所指向的字符串常量初始化string对象(eg:string s2="abc";)
//string(const string& rhs);//复制构造函数(eg:string s3=s2;)
//string类常用操作:string s1="abc",s2="def";string s3=s1+s2;//结果是“abcdef”
//bool s4=(s1<s2);//结果是true   char s5=s2[1];//结果是‘e'



//--------------string类应用-------------------
#include <iostream>
#include <string>
using namespace  std;
//根据value的值输出true或false
//title为提示文字
inline void test(const char *title,bool value)
{
    cout<<title<<"returns"<<(value?"true":"false")<<endl;
}
int main()
{
    string s1="DEF";
    cout<<"s1 is"<<s1<<endl;
    string s2;
    cout<<"Please enter s2:";
    cin>>s2;
    cout<<"length of s2:"<<s2.length()<<endl;

    //比较运算符的测试
    test("s1<=\"ABC\"",s1<="ABC");
    test("\"DEF\"<=s1","DEF"<=s1);
    //连接运算符的测试
    s2+=s1;
    cout<<"s2=s2+s1:"<<s2<<endl;
    cout<<"length of s2:"<<s2.length()<<endl;
    return 0;
}
//输入整行字符串
//getline可以输如整行字符串(要包含sting头文件),eg:getline(cin,s2);
//输入字符串时,可以使用其他分隔符作为字符串结束的标志(逗号、分号),将分隔符作为getline的第3个参数即可，eg:getline(cin,s2,',');
//--------------用getline输入字符串-------------------
#include <iostream>
#include <string>
using namespace std;
int main()
{
    for(int i=0;i<2;i++)
    {
        string city,state;
        getline(cin,city,',');
        getline(cin,state);
        cout<<"City:"<<city<<" State:"<<state<<endl;
    }
    return 0;
}
